﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WF_QLThuVien.Utilities
{
    public static class CXuLiChuoi
    {
        public static string LayKiTuDauMoiChu(string chuoi)
        {
            string s = CatKhoangTrang(chuoi.Trim());
            int i = 1;
            string temp = s[0].ToString().ToUpper();
            while (i < s.Length)
            {
                if (s[i] == ' ')
                {
                    temp += s[i + 1].ToString().ToUpper();
                }
                i++;
            }
            return temp;
        }

      
        public static string VietHoaDauMoiChu(string chuoi)
        {
            string s = CatKhoangTrang(chuoi.Trim()).ToLower();
            string temp = s[0].ToString().ToUpper();
            int i = 1;
            while (i < s.Length)
            {
                if (s[i] == ' ')
                {
                    temp += " " + s[i + 1].ToString().ToUpper();
                    i += 2;
                }
                else
                {
                    temp += s[i].ToString();
                    i++;
                }

            }
            return temp;
        }

        public static string CatKhoangTrang(string str)
        {
            string tmp = str.Trim();
            while (tmp.Contains("  "))
            {
                tmp = tmp.Replace("  ", " ");
            }
            return tmp;
        }
    }
}

